package com.draw.cli.gui.panel.config;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JScrollPane;

import com.draw.cli.gui.panel.Refreshable;

public class ConfigPanel extends JPanel implements ActionListener , Refreshable {
	private static final long serialVersionUID = 1370619459876236315L;

	private static ConfigPanel instance = new ConfigPanel();
	
	public static ConfigPanel getInstance() {
		return instance;
	}

	private ServerConfigPanel server;
	private ProxyConfigPanel proxy;

	private JButton okButton;
	private JButton cancelButton;
	
	public ConfigPanel() {
		this.setLayout(new BorderLayout());
		JPanel pan = new JPanel();
		BoxLayout lay = new BoxLayout(pan,BoxLayout.Y_AXIS);
		pan.setLayout(lay);
		this.server = new ServerConfigPanel();
		pan.add(this.server);
		this.proxy = new ProxyConfigPanel();
		pan.add(this.proxy);

		JScrollPane scroll = new JScrollPane(pan);
		scroll.setAlignmentX(LEFT_ALIGNMENT);
		this.add(scroll, BorderLayout.CENTER);
		
		JPanel south = new JPanel(new FlowLayout(FlowLayout.RIGHT));
		
		okButton = new JButton("OK");
		okButton.addActionListener(this);
		south.add(okButton);
		cancelButton = new JButton("Annuler");
		cancelButton.addActionListener(this);
		south.add(cancelButton);
		
		this.add(south,BorderLayout.SOUTH);
	}

	@Override
	public void actionPerformed(ActionEvent arg0) {
		if (this.okButton.equals(arg0.getSource())) {
			this.proxy.ok();
			this.server.ok();
		}
		if (this.cancelButton.equals(arg0.getSource())) {
			this.proxy.cancel();
			this.server.cancel();
		}
	}

	@Override
	public void refresh() {
		// TODO Auto-generated method stub
		
	}
}
